import axios from 'axios';

export default {
    install: function(Vue, options) {

        let service = {
            // 查询符合条件的比赛数量
            QueryCompetesCount: (condition) => {
                return axios.post('/admin/compete/query/count', condition);
            },

            // 查询符合条件的比赛
            QueryCompetes: (condition, pageIndex, pageSize) => {
                return axios.post(`/admin/compete/query?pageIndex=${pageIndex}&pageSize=${pageSize}`, condition);
            },

            // 查询所有未分配比赛的分类数量
            QueryUnassignedCount: () => {
                return axios.get('/admin/compete/query/unassigned/count');
            },

            // 查询所有未分配比赛列表
            QueryUnassignedCompetes: (event, group) => {
                return axios.get(`/admin/compete/query/unassigned/${event}/${group}`);
            },

            // 导出比赛列表
            ExportCompetes: (condition) => {
                return axios.post('/admin/compete/export', condition)
                    .then(ret => {
                        var link = aphf.file.ADDR + '/' + ret;

                        var a = document.createElement("a");
                        a.download = 'Competes.xls';
                        a.href = link;
                        a.click();
                    })
            }
        }

        Vue.prototype.$CompeteService = service;
    }
}